for, Control structures


Prototype:

for (expr1; expr2; expr3) statement

Description:

for loops are the most complex loops. They behave similar to their C counterparts.

The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.
In the beginning of each iteration, expr2 is evaluated. If it evaluates to true, the loop continues and the nested statement(s) are executed. If it evaluates to false, the execution of the loop ends.

At the end of each iteration, expr3 is evaluated (executed).
Each of the expressions can be empty. expr2 being empty means the loop should be run indefinitely (PHP implicitly considers it as true, like C). This may not be as useless as you might think, since often you'd want to end the loop using a conditional break statement instead of using the for truth expression.

Example
for (var i=0, var j="test";i<=10;i++) {
	echo i;
}

for (var i=0;i<=10;i++) {
	echo i;
}

for (var i=0;;i++) {
	if (i>10)
		break;
	echo i;
}

var i=0;
for (;;) {
	if (i>10)
		break;
	i++;
}